﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Controls;
using WPFHelpers;

namespace Tourbook.Riders
{
    public class EmailValidationRule : ValidationRule
    {
        public override ValidationResult Validate(object value, System.Globalization.CultureInfo cultureInfo)
        {
            string email = value as string;
            if (null == email)
            {
                return new ValidationResult(false, "value is not a string");
            }
            if (String.IsNullOrEmpty(email) || RegexHelper.IsValid(email, @"^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,4})$"))
            {
                return new ValidationResult(true, null);
            }
            return new ValidationResult(false, "Enter none or a valid Email address");
        }
    }
}
